package org.andcool.util;

import android.util.Log;

/**
 * @author Joosun
 * @since 2011-8-12
 */
public class Debug
{
	private static String sDebugTag = "AndCool";
	private static DebugLevel sDebugLevel = DebugLevel.ALL;

	public static String getDebugTag()
	{
		return Debug.sDebugTag;
	}

	public static void setDebugTag(final String pDebugTag)
	{
		Debug.sDebugTag = pDebugTag;
	}

	public static DebugLevel getDebugLevel()
	{
		return Debug.sDebugLevel;
	}

	public static void setDebugLevel(final DebugLevel pDebugLevel)
	{
		Debug.sDebugLevel = pDebugLevel;
	}

	// VERBOSE
	public static void v(final String pMessage)
	{
		Debug.v(pMessage, null);
	}

	public static void v(final Throwable pThrowable)
	{
		Debug.v("", pThrowable);
	}

	public static void v(final String pMessage, final Throwable pThrowable)
	{
		if (Debug.sDebugLevel.isSameOrLessThan(DebugLevel.VERBOSE))
		{
			Log.v(Debug.sDebugTag, pMessage, pThrowable);
		}
	}

	// DEBUG
	public static void d(final String pMessage)
	{
		Debug.d(pMessage, null);
	}

	public static void d(final Throwable pThrowable)
	{
		Debug.d("", pThrowable);
	}

	public static void d(final String pMessage, final Throwable pThrowable)
	{
		if (Debug.sDebugLevel.isSameOrLessThan(DebugLevel.DEBUG))
		{
			Log.d(Debug.sDebugTag, pMessage, pThrowable);
		}
	}

	// INFO
	public static void i(final String pMessage)
	{
		Debug.i(pMessage, null);
	}

	public static void i(final Throwable pThrowable)
	{
		Debug.i("", pThrowable);
	}

	public static void i(final String pMessage, final Throwable pThrowable)
	{
		if (Debug.sDebugLevel.isSameOrLessThan(DebugLevel.INFO))
		{
			Log.i(Debug.sDebugTag, pMessage, pThrowable);
		}
	}

	// WARNING
	public static void w(final String pMessage)
	{
		Debug.w(pMessage, null);
	}

	public static void w(final Throwable pThrowable)
	{
		Debug.w("", pThrowable);
	}

	public static void w(final String pMessage, final Throwable pThrowable)
	{
		if (Debug.sDebugLevel.isSameOrLessThan(DebugLevel.WARNING))
		{
			Log.w(Debug.sDebugTag, pMessage, pThrowable);
		}
	}

	// ERROR
	public static void e(final String pMessage)
	{
		Debug.e(pMessage, null);
	}

	public static void e(final Throwable pThrowable)
	{
		Debug.e("", pThrowable);
	}

	public static void e(final String pMessage, final Throwable pThrowable)
	{
		if (Debug.sDebugLevel.isSameOrLessThan(DebugLevel.ERROR))
		{
			Log.e(Debug.sDebugTag, pMessage, pThrowable);
		}
	}

	public static enum DebugLevel implements Comparable<DebugLevel>
	{
		NONE,
		ERROR,
		WARNING,
		INFO,
		DEBUG,
		VERBOSE;

		public static DebugLevel ALL = DebugLevel.VERBOSE;

		protected boolean isSameOrLessThan(final DebugLevel pDebugLevel)
		{
			return this.compareTo(pDebugLevel) >= 0;
		}
	}
}